/**
 * Generate code from /{{projectName}}-core/src/main/java/{{packageName}}/core/{{modules}}/domain/{{entities@SQL}}.java.hbs
 */
package cn.ibizlab.core.oauth2.domain;

import java.util.*;
import cn.ibizlab.util.domain.IEntity;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.*;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import org.springframework.util.*;
import org.springframework.data.annotation.*;
import cn.ibizlab.util.annotation.*;
import cn.ibizlab.util.enums.*;
import cn.ibizlab.util.domain.EntityMP;
import java.io.Serializable;
import lombok.*;
import lombok.experimental.Accessors;
import io.swagger.annotations.*;
import com.baomidou.mybatisplus.annotation.*;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import cn.ibizlab.core.oauth2.domain.OauthClientDetails;

/**
 * 认证授权Token记录实体类[OauthAccessToken]
 *
 * @author generator
 */
@Getter
@Setter
@NoArgsConstructor
@Accessors(chain = true)
@JsonIgnoreProperties(value = "handler")
@TableName(value = "oauth_access_token", resultMap = "OauthAccessTokenResultMap")
@ApiModel(value = "OAUTH_ACCESS_TOKEN", description = "认证授权Token记录")
public class OauthAccessToken extends EntityMP implements Serializable
{

    /**
     * 标识
     */
    @Id
    @TableId(value = "authentication_id" , type = IdType.ASSIGN_UUID)
    @DEField(name = "authentication_id" , isKeyField = true)
    @JsonProperty("authentication_id")
    @JSONField(name = "authentication_id")
    @ApiModelProperty(value = "authentication_id", notes = "标识")
    private String authenticationId;

    /**
     * token标识
     */
    @TableField(value = "token_id")
    @DEField(name = "token_id")
    @JsonProperty("token_id")
    @JSONField(name = "token_id")
    @ApiModelProperty(value = "token_id", notes = "token标识")
    private String tokenId;

    /**
     * token
     */
    @TableField(value = "token", typeHandler = cn.ibizlab.util.helper.typehandler.ByteArrayToStringTypeHandler.class)
    @DEField(name = "token")
    @JsonProperty("token")
    @JSONField(name = "token")
    @ApiModelProperty(value = "token", notes = "token")
    private String token;

    /**
     * 客户端标识
     */
    @TableField(value = "client_id")
    @DEField(name = "client_id")
    @JsonProperty("client_id")
    @JSONField(name = "client_id")
    @ApiModelProperty(value = "client_id", notes = "客户端标识")
    private String clientId;

    /**
     * 用户全局名
     */
    @TableField(value = "user_name")
    @DEField(name = "user_name")
    @JsonProperty("user_name")
    @JSONField(name = "user_name")
    @ApiModelProperty(value = "user_name", notes = "用户全局名")
    private String userName;

    /**
     * authentication
     */
    @TableField(value = "authentication", typeHandler = cn.ibizlab.util.helper.typehandler.ByteArrayToStringTypeHandler.class)
    @DEField(name = "authentication")
    @JsonProperty("authentication")
    @JSONField(name = "authentication")
    @ApiModelProperty(value = "authentication", notes = "authentication")
    private String authentication;

    /**
     * RefreshToken标识
     */
    @TableField(value = "refresh_token")
    @DEField(name = "refresh_token")
    @JsonProperty("refresh_token")
    @JSONField(name = "refresh_token")
    @ApiModelProperty(value = "refresh_token", notes = "RefreshToken标识")
    private String refreshToken;

    /**
     * oauth客户端信息
     */
    @JsonIgnore
    @JSONField(serialize = false)
    @TableField(exist = false)
    @Transient
    @ApiModelProperty(value = "oauth_client_details", notes = "client")
    private OauthClientDetails oauthClientDetails;

    /**
     * 设置 [token标识]
     */
    public OauthAccessToken setTokenId(String tokenId) {
        this.tokenId = tokenId;
        this.modify("token_id", tokenId);
        return this;
    }

    /**
     * 设置 [token]
     */
    public OauthAccessToken setToken(String token) {
        this.token = token;
        this.modify("token", token);
        return this;
    }

    /**
     * 设置 [客户端标识]
     */
    public OauthAccessToken setClientId(String clientId) {
        this.clientId = clientId;
        this.modify("client_id", clientId);
        return this;
    }

    /**
     * 设置 [用户全局名]
     */
    public OauthAccessToken setUserName(String userName) {
        this.userName = userName;
        this.modify("user_name", userName);
        return this;
    }

    /**
     * 设置 [authentication]
     */
    public OauthAccessToken setAuthentication(String authentication) {
        this.authentication = authentication;
        this.modify("authentication", authentication);
        return this;
    }

    /**
     * 设置 [RefreshToken标识]
     */
    public OauthAccessToken setRefreshToken(String refreshToken) {
        this.refreshToken = refreshToken;
        this.modify("refresh_token", refreshToken);
        return this;
    }

    /**
     * 复制当前对象数据到目标对象(粘贴重置)
     * @param targetEntity 目标数据对象
     * @param includeEmpty  是否包括空值
     * @param <T>
     * @return
     */
    @Override
    public <T> T pasteTo(T targetEntity, boolean includeEmpty) {
        super.pasteTo(targetEntity, includeEmpty);
        if(targetEntity instanceof IEntity) {
            IEntity entity = ((IEntity) targetEntity);
            entity.reset("authentication_id");
        }
        return targetEntity;
    }

}